package com.xpm.activity;

import android.util.Log;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.xpm.adapter.muliti.MulitiTypeAdapter;
import com.xpm.base.BaseActivity;
import com.xpm.databinding.ActivityMultiTypeBinding;
import com.xpm.entity.DataProvider;
import com.xpm.entity.MulitTypeBean;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class MultiTypeActivity extends BaseActivity<ActivityMultiTypeBinding> {

    private RecyclerView recyclerView;
    private List<MulitTypeBean> mDatas;

    @Override
    protected ActivityMultiTypeBinding getBinding() {
        return ActivityMultiTypeBinding.inflate(getLayoutInflater());
    }


    @Override
    protected void initView() {
        setTitle("多类型RecycleView");
        recyclerView = binding.recycleView;
    }

    @Override
    protected void initData() {
        // 准备初始化数据
        mDatas = new ArrayList<>();
        Random random = new Random();
        for (int i = 0; i < DataProvider.icons.length; i++){
            MulitTypeBean bean = new MulitTypeBean();
            bean.type= random.nextInt(3);
            Log.i("Type", bean.type+"@");
            bean.pic = DataProvider.icons[i];
            bean.title = "title "+ i;
            mDatas.add(bean);
        }
        // 布局管理器
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        layoutManager.setReverseLayout(false);
        // 给RecycleView设置布局管理器
        recyclerView.setLayoutManager(layoutManager);
        // 创建适配器
        MulitiTypeAdapter adapter = new MulitiTypeAdapter(mDatas);
        // 设置适配器
        recyclerView.setAdapter(adapter);



    }

    @Override
    protected void initListener() {

    }
}